package api

import (
	"io"
	"net/http"
	"os"

	"openzbox.com/frame/echo"
)

func GetDmesg(c echo.Context) error {
	/*
		info := utils.Response{Code: 1, Desc: "System will cold restart after 10 second.."}
		return c.JSON(http.StatusOK, info)
	*/
	//err := core.Mybox.RunShellCommand("dmesg > mbox.log")
	//if err != nil {
	//	//fmt.Println("read fail", err)
	//	return c.String(http.StatusOK, err.Error())
	//}

	// f, err := os.Open("./mbox.log")
	f, err := os.Open("./log/20230730.log")
	if err != nil {
		//fmt.Println("read fail", err)
		return c.String(http.StatusOK, err.Error())
	}
	defer f.Close()

	//r := bufio.NewReader(f)
	r := io.LimitReader(f, 1024*1024)
	//return c.String(http.StatusOK, string(f))
	return c.Stream(http.StatusOK, "txt", r)
}
